package avicit.bdp.dms.das.rest;

import avicit.bdp.dms.das.dto.StorageGroupDTO;
import avicit.bdp.dms.das.service.StorageGroupService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 存储组管理REST接口
 */
@RestController
@Api(tags = "存储组管理REST接口")
@RequestMapping("/api/bdp/dms/das/storagegroup")
public class StorageGroupRest {

    @Autowired
    private StorageGroupService storageGroupService;

    /**
     * 新增存储组对象
     */
    @PostMapping("/insertStorageGroup")
    @ApiOperation(value = "新增对象")
    public ResponseMsg<String> insertStorageGroup(@RequestBody StorageGroupDTO storageGroup) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(storageGroupService.insertStorageGroup(storageGroup));
        return responseMsg;
    }

    /**
     * 修改存储组对象
     */
    @PostMapping("/updateStorageGroup")
    @ApiOperation(value = "修改对象")
    public ResponseMsg<String> updateStorageGroup(@RequestBody  StorageGroupDTO storageGroup) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        storageGroupService.updateStorageGroup(storageGroup);
        return responseMsg;
    }


    /**
     * 删除存储组对象
     */
    @PostMapping("/deleteStorageGroup")
    @ApiOperation(value = "按主键单条删除")
    public ResponseMsg<String> deleteById(@RequestBody StorageGroupDTO storageGroup) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        storageGroupService.deleteStorageGroupById(storageGroup.getId());
        return responseMsg;
    }

    /**
     * 按条件分页查询存储组列表
     */
    @ApiOperation(value = "按条件分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "关键词", name = "keyword", dataType = "String"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Integer"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Integer")
    })
    @GetMapping("/getStorageGroupList")
    public ResponseMsg<QueryRespBean<StorageGroupDTO>> getStorageGroupList(
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        ResponseMsg<QueryRespBean<StorageGroupDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<StorageGroupDTO> result = storageGroupService.getStorageGroupList(keyword, pageNo, pageSize);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    /**
     * 按关键字查询
     */
    @ApiOperation(value = "按条件查询")
    @ApiImplicitParam(value = "关键词", name = "keyword", dataType = "String")
    @GetMapping("/getStorageGroupListByKeyword")
    public ResponseMsg<List<StorageGroupDTO>> getStorageGroupListByKeyword(
            @RequestParam(required = false) String keyword) {

        ResponseMsg<List<StorageGroupDTO>> responseMsg = new ResponseMsg<>();
        List<StorageGroupDTO> result = storageGroupService.getStorageGroupListByKeyword(keyword);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

}